﻿Imports Capa_de_Acceso_a_Datos

Public Class frmCompararCaratulas

    Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalir.Click
        Me.Dispose()
    End Sub

    Private Sub frmCompararCaratulas_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Me.Dispose()
    End Sub

    Private Sub CompararCaratulas_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        With dgvComparacionCaratulas
            ' alternar color de filas  
            .AlternatingRowsDefaultCellStyle.BackColor = Color.FloralWhite
            .DefaultCellStyle.BackColor = Color.Beige
        End With

        CargarCombos()
    End Sub

    Private Sub CargarCombos()
        'Combo Año
        cboAno.ValueMember = "AnoId"
        cboAno.DisplayMember = "Ano"
        cboAno.DataSource = Constante.obtenerAnos

        'Combo Mes 
        cboMes.ValueMember = "MesId"
        cboMes.DisplayMember = "MesNombre"
        cboMes.DataSource = MesDAO.obtenerMeses(0)
        cboMes.SelectedValue = Date.Now.Month

        'Combo ObraSocialXPlan
        cboObraSocial.ValueMember = "ObraSocialXPlanId"
        cboObraSocial.DisplayMember = "Descripcion"
        cboObraSocial.DataSource = ObraSocialXPlanDAO.comboObraSocialXPlan()

    End Sub

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click

        'Si ObraSocialXPlanId - Año - Mes esta cerrada
        If ObraSocialCerrada() Then
            CargarGrilla()
        End If

    End Sub

    Private Sub CargarGrilla()
        Dim ObraSocialXPlanId As Integer = cboObraSocial.SelectedValue
        Dim AnoId As Integer = cboAno.SelectedValue
        Dim MesId As Integer = cboMes.SelectedValue

        dgvComparacionCaratulas.DataSource = CaratulaPresentacionDAO.obtenerCerradasXOS(ObraSocialXPlanId, AnoId, MesId)
        dgvComparacionCaratulas.Refresh()
        dgvComparacionCaratulas.Columns("PresentacionId").Visible = False
        dgvComparacionCaratulas.Columns("FarmaciaNombre").HeaderText = "Farmacia"
        dgvComparacionCaratulas.Columns("RecetasOriginal").HeaderText = "Recetas Original"
        dgvComparacionCaratulas.Columns("TotalOriginal").HeaderText = "Facturado Original"
        dgvComparacionCaratulas.Columns("ACargoOSOriginal").HeaderText = "A Cargo Original"
        dgvComparacionCaratulas.Columns("RecetasIntermedia").HeaderText = "Recetas Intermedia"
        dgvComparacionCaratulas.Columns("TotalIntermedia").HeaderText = "Facturado Intermedia"
        dgvComparacionCaratulas.Columns("ACargoOSIntermedia").HeaderText = "A Cargo Intermedia"

    End Sub

    Private Function ObraSocialCerrada() As Boolean
        Dim ObraSocialXPlanId As Integer = cboObraSocial.SelectedValue
        Dim AnoId As Integer = cboAno.SelectedValue
        Dim MesId As Integer = cboMes.SelectedValue
        Dim retorno As Boolean = False

        If CierreObraSocialDAO.ObraSocialCerrada(MesId, AnoId, ObraSocialXPlanId) Then
            retorno = True
        End If

        Return retorno
    End Function

End Class